package com.bandi.tharshesnows;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;

public class BaseActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /*ActionBar actionbar = getSherlock().getActionBar();
    actionbar.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    actionbar.setDisplayShowTitleEnabled(false);*/
  }

  protected void showFailedAlert(final String message) {
    runOnUiThread(new Runnable() {

      @Override
      public void run() {
        AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this);
        builder.setMessage(message);
        builder.setTitle("Alerta");
        builder.setPositiveButton("Incearca mai tarziu", new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
          }
        });
        builder.create().show();
      }
    });
  }

  protected void showAlert(final String title, final String message, final String positiveBtn) {
    runOnUiThread(new Runnable() {

      @Override
      public void run() {
        AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this);
        builder.setMessage(message);
        builder.setTitle(title);
        builder.setPositiveButton(positiveBtn, new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
          }
        });
        builder.create().show();
      }
    });
  }

  public boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
      return true;
    }
    return false;
  }

}
